﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Content;

namespace FHOClient
{
    public class LoginScreen
    {
        public HUDImageObject logo = new HUDImageObject();
        public HUDImageObject loginButton = new HUDImageObject();
        public HUDTextBoxObject userNameBox = new HUDTextBoxObject();
        public HUDTextBoxObject passwordBox = new HUDTextBoxObject();
        private ContentManager content;


        


        public void Initialize(GraphicsDeviceManager graphics, ContentManager Content)
        {
            content = Content;
            logo.Setup(graphics, "Content\\FHOLogo.bmp", Color.White);
            loginButton.Setup(graphics, "Content\\FHOLoginButton.bmp", Color.White);
            userNameBox.Setup(graphics, "Content\\FHOUserName.bmp", Color.White);
            passwordBox.Setup(graphics, "Content\\FHOPassword.bmp", Color.White);
            logo.X = (graphics.GraphicsDevice.Viewport.Width / 2) - (logo.Width / 2);
            logo.Y = 20;
            userNameBox.X = (graphics.GraphicsDevice.Viewport.Width / 2) - (userNameBox.Width / 2);
            userNameBox.Y = (graphics.GraphicsDevice.Viewport.Height / 2) - (userNameBox.Height / 2);
            userNameBox.TextData = "";
            userNameBox.displayTextData = "";
            passwordBox.X = userNameBox.X;
            passwordBox.Y = userNameBox.Y + 120;
            passwordBox.TextData = "";
            passwordBox.displayTextData = "";
            passwordBox.IsPassword = true;
            loginButton.X = (graphics.GraphicsDevice.Viewport.Width / 2) - (loginButton.Width / 2);
            loginButton.Y = passwordBox.Y + 150;
        }

        public void GetMouseClick(MouseState aMouse)
        {
            if ((aMouse.X > userNameBox.X) & (aMouse.X < userNameBox.X + userNameBox.Width))
            {
                if ((aMouse.Y > userNameBox.Y) & (aMouse.Y < userNameBox.Y + userNameBox.Height))
                {
                    userNameBox.IsSelected = true;
                }
                else
                {
                    userNameBox.IsSelected = false;
                    
                }
            }
            else
            {
                userNameBox.IsSelected = false;
            }

            if ((aMouse.X > passwordBox.X) & (aMouse.X < passwordBox.X + passwordBox.Width))
            {
                if ((aMouse.Y > passwordBox.Y) & (aMouse.Y < passwordBox.Y + passwordBox.Height))
                {
                    passwordBox.IsSelected = true;
                }
                else
                {
                    passwordBox.IsSelected = false;
                }
            }
            else
            {
                passwordBox.IsSelected = false;
            }
            if ((aMouse.X > loginButton.X) & (aMouse.X < loginButton.X + loginButton.Width))
            {
                if ((aMouse.Y > loginButton.Y) & (aMouse.Y < loginButton.Y + loginButton.Height))
                {
                    //passwordBox.IsSelected = true;
                }
            }
        }

        public void UpdateTextBox(KeyboardState keyboardState)
        {
            if (userNameBox.IsSelected)
            {
                userNameBox.UpdateText(keyboardState);
            }
            if (passwordBox.IsSelected)
            {
                passwordBox.UpdateText(keyboardState);
            }
        }

        public void DrawScreen(GraphicsDeviceManager graphics, SpriteBatch spriteBatch)
        {
            SpriteFont fontArial;
            fontArial = content.Load<SpriteFont>("Arial");
            spriteBatch.Draw(logo.Picture, new Rectangle(logo.X, logo.Y, logo.Width, logo.Height), Color.White);
            spriteBatch.Draw(userNameBox.Picture, new Rectangle(userNameBox.X, userNameBox.Y, userNameBox.Width, userNameBox.Height), Color.White);
            spriteBatch.Draw(passwordBox.Picture, new Rectangle(passwordBox.X, passwordBox.Y, passwordBox.Width, passwordBox.Height), Color.White);
            if (userNameBox.IsSelected)
            {
                spriteBatch.DrawString(fontArial, userNameBox.displayTextData + "_", new Vector2(userNameBox.X + 10, userNameBox.Y + 80), Color.Yellow);
            }
            else
            {
                spriteBatch.DrawString(fontArial, userNameBox.displayTextData, new Vector2(userNameBox.X + 10, userNameBox.Y + 80), Color.DarkKhaki);
            }
            if (passwordBox.IsSelected)
            {
                spriteBatch.DrawString(fontArial, passwordBox.displayTextData + "_", new Vector2(passwordBox.X + 10, passwordBox.Y + 80), Color.Yellow);
            }
            else
            {
                spriteBatch.DrawString(fontArial, passwordBox.displayTextData, new Vector2(passwordBox.X + 10, passwordBox.Y + 80), Color.DarkKhaki);
            }
            spriteBatch.Draw(loginButton.Picture, new Rectangle(loginButton.X, loginButton.Y, loginButton.Width, loginButton.Height), Color.White);
        }
    }
}
